package com.lovo.commodity.service.impl;

import com.alibaba.fastjson.JSON;
import com.lovo.commodity.dao.IESCommodityDAO;
import com.lovo.commodity.service.IESCommodityService;
import com.lovo.common.bean.CommodityBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ESCommodityServiceImpl implements IESCommodityService {
    @Resource
    private IESCommodityDAO commodityDAO;
    @Resource
    private ElasticsearchRestTemplate elasticsearchRestTemplate;
    @Override
    public List<CommodityBean> findAllByCommName(String name) {
        return commodityDAO.findAllByCommName(name);
    }

    @Override
    public List<CommodityBean> findByName(String name) {
        return commodityDAO.findByName(name);

    }

    @Override
    public CommodityBean findById(Long id) {

        return commodityDAO.findById(id).orElse(null);
    }

    @Override
    public void save(CommodityBean commodityBean) {
        commodityDAO.save(commodityBean);
    }

    @Override
    public void delete(Long id) {
        commodityDAO.deleteById(id);
    }
}
